this.BX=this.BX||{};this.BX.Desktop=this.BX.Desktop||{};this.BX.Desktop.Field=this.BX.Desktop.Field||{};(function(e,t,i,a,l){"use strict";i=i&&i.hasOwnProperty("default")?i["default"]:i;var n,s,r,o;var u=function(){function e(t){var i=this;babelHelpers.classCallCheck(this,e);babelHelpers.defineProperty(this,"targetNode",null);babelHelpers.defineProperty(this,"wrapper",null);babelHelpers.defineProperty(this,"valuesWrapper",null);babelHelpers.defineProperty(this,"input",null);babelHelpers.defineProperty(this,"dialogSelector",null);babelHelpers.defineProperty(this,"tagSelector",null);babelHelpers.defineProperty(this,"selectedItems",new Set);babelHelpers.defineProperty(this,"items",new Set);babelHelpers.defineProperty(this,"messages",[]);this.targetNode=document.getElementById(t.targetNodeId);if(this.targetNode===null){throw new Error("Target node: ".concat(t.targetNodeId," not found"))}this.fieldName=t.fieldName.toLowerCase();this.fieldNameForEvent=t.fieldNameForEvent;this.fieldTitle=t.fieldTitle;this.context=t.context;this.messages=t.messages;this.isMultiple=t.isMultiple==="true";this.prepareItems(t);this.createWrappers();if(this.isMultiple){a.Runtime.loadExtension("ui.entity-selector").then(function(e){i.tagSelector=i.getTagSelector(e.TagSelector);i.tagSelector.renderTo(i.wrapper);i.adjustLayout(false)})}else{a.Runtime.loadExtension("ui.entity-selector").then(function(e){i.dialogSelector=i.getDialogSelector(e.Dialog);i.prepareInput(i.targetNode);a.Event.bind(i.targetNode,"click",function(){i.show()});if(i.selectedItems.size){var t=babelHelpers.toConsumableArray(i.selectedItems);i.input.value=t[0].title}i.adjustLayout(false)})}}babelHelpers.createClass(e,[{key:"prepareItems",value:function e(t){var i=this;var a=t.items;if(!Array.isArray(a)){if(a===""){return}a=[a]}var l=this.fieldName;a.forEach(function(e){var t={id:e.VALUE,entityId:l,title:e.NAME,tabs:l};i.items.add(t);if(e.IS_SELECTED===true){i.selectedItems.add(t)}})}},{key:"prepareInput",value:function e(t){this.input=a.Tag.render(n||(n=babelHelpers.taggedTemplateLiteral(['\n\t\t\t<input \n\t\t\t\tname="','_input" \n\t\t\t\ttype="text" \n\t\t\t\tclass="ui-ctl-element main-ui-control main-enum-dialog-input" \n\t\t\t\tautocomplete="off"\n\t\t\t/>\n\t\t'])),t.id);a.Dom.append(this.input,t);var i=this.dialogSelector;var l=this.input;a.Event.bind(this.input,"keyup",function(e){if(!l.value.length){i.search("");i.clearSearch();i.deselectAll();i.hide()}else{var t=i.getSelectedItems();if(!t.some(function(e){return e.title.getText()===l.value})){i.show();i.clearSearch();i.search(l.value)}}})}},{key:"createWrappers",value:function e(){this.createWrapper();this.createValuesWrapper()}},{key:"createWrapper",value:function e(){this.wrapper=a.Tag.render(s||(s=babelHelpers.taggedTemplateLiteral(['<div class="ui-ctl-w100"></div>'])));this.targetNode.appendChild(this.wrapper)}},{key:"createValuesWrapper",value:function e(){this.valuesWrapper=a.Tag.render(r||(r=babelHelpers.taggedTemplateLiteral(["<div></div>"])));this.wrapper.appendChild(this.valuesWrapper)}},{key:"show",value:function e(){this.dialogSelector.show()}},{key:"getDialogSelector",value:function e(t){var i=this.getDialogOptions();i.targetNode=this.targetNode;i.events={"Item:onSelect":this.onElementSelect.bind(this),"Item:onDeselect":this.onElementDeselect.bind(this)};return new t(i)}},{key:"getTagSelector",value:function e(t){return new t({addButtonCaption:this.getMessage("addButtonCaption"),addButtonCaptionMore:this.getMessage("addButtonCaptionMore"),showCreateButton:false,dialogOptions:this.getDialogOptions(),items:this.getDialogSelectedItems(),height:240,textBoxWidth:"100%",events:{onTagAdd:this.onElementSelect.bind(this),onTagRemove:this.onElementDeselect.bind(this)}})}},{key:"getDialogOptions",value:function e(){return{context:this.context,items:this.getDialogItems(),selectedItems:this.getDialogSelectedItems(),height:240,dropdownMode:true,showAvatars:false,compactView:true,multiple:this.isMultiple,enableSearch:false,tabs:[{id:this.fieldName,title:this.fieldTitle}]}}},{key:"getDialogItems",value:function e(){return babelHelpers.toConsumableArray(this.items)}},{key:"getDialogSelectedItems",value:function e(){return babelHelpers.toConsumableArray(this.selectedItems)}},{key:"onElementSelect",value:function e(t){var i=this.getItemFromEventData(t);if(!this.isMultiple){this.selectedItems.clear();this.input.value=i.getTitle()}this.selectedItems.add(this.createOption(i));this.adjustLayout()}},{key:"onElementDeselect",value:function e(t){var i=this.getItemFromEventData(t);var a=this.createOption(i);if(!this.isMultiple){this.selectedItems.clear();this.input.value=""}this.selectedItems=new Set(babelHelpers.toConsumableArray(this.selectedItems).filter(function(e){return JSON.stringify(e)!==JSON.stringify(a)}));this.adjustLayout()}},{key:"getItemFromEventData",value:function e(t){return this.isMultiple?t.getData().tag:t.getData().item}},{key:"createOption",value:function e(t){return{id:t.id,entityId:this.fieldName,title:t.title,tabs:this.fieldName}}},{key:"adjustLayout",value:function e(){var t=this;var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;this.clearValueItems();if(this.selectedItems.size){this.selectedItems.forEach(function(e){t.adjustItem(e.id)})}else{this.adjustItem("")}if(i){BX.fireEvent(document.getElementById(this.fieldNameForEvent),"change")}}},{key:"clearValueItems",value:function e(){this.valuesWrapper.innerHTML=""}},{key:"adjustItem",value:function e(t){this.valuesWrapper.appendChild(this.createInputTag(t))}},{key:"createInputTag",value:function e(t){return a.Tag.render(o||(o=babelHelpers.taggedTemplateLiteral(['\n\t\t\t<input name="','" type="hidden" value="','"/>\n\t\t'])),this.fieldName.toUpperCase(),t)}},{key:"getMessage",value:function e(t){var i;return(i=this.messages[t])!==null&&i!==void 0?i:null}}]);return e}();var d=function(){function e(t){babelHelpers.classCallCheck(this,e);babelHelpers.defineProperty(this,"fieldName",null);babelHelpers.defineProperty(this,"container",null);babelHelpers.defineProperty(this,"valueContainerId",null);babelHelpers.defineProperty(this,"value",null);babelHelpers.defineProperty(this,"items",null);babelHelpers.defineProperty(this,"defaultFieldName",null);babelHelpers.defineProperty(this,"block",null);babelHelpers.defineProperty(this,"formName",null);babelHelpers.defineProperty(this,"params",{});this.fieldName=t["fieldName"]||"";this.container=document.getElementById(t["container"]);this.valueContainerId=t["valueContainerId"]||"";this.value=t["value"];this.items=t["items"];this.block=t["block"];this.defaultFieldName=t["defaultFieldName"]||this.fieldName+"_default";this.formName=t["formName"]||"";this.params=t["params"]||{};this.bindElement()}babelHelpers.createClass(e,[{key:"bindElement",value:function e(){this.container.appendChild(BX.decl({block:this.block,name:this.fieldName,items:this.items,value:this.value,params:this.params,valueDelete:false}));this.onChangeHandler=this.onChange.bind(this);l.EventEmitter.subscribe("UI::Select::change",this.onChangeHandler);BX.bind(this.container,"click",BX.defer(function(){this.onChange({params:this.params,node:this.container.firstChild})}.bind(this)))}},{key:"onChange",value:function e(t){var i;if(t instanceof l.BaseEvent){var a=t.getData();i=a[0]}else{i=t}if(!document.getElementById(this.valueContainerId)){return}var n=null;if(i.node!==null&&i.node.getAttribute("data-name")===this.fieldName){n=JSON.parse(i.node.getAttribute("data-value"))}else{return}this.changeValue(n)}},{key:"changeValue",value:function e(t){var i="";if(!a.Type.isArray(t)){if(t===null){t=[{VALUE:""}]}else{t=[t]}}if(t.length>0){for(var l=0;l<t.length;l++){i+='<input type="hidden" name="'.concat(this.fieldName,'" value="').concat(a.Text.encode(t[l].VALUE),'" />')}}else{i+='<input type="hidden" name="'.concat(this.fieldName,'" value="" />')}document.getElementById(this.valueContainerId).innerHTML=i;BX.fireEvent(document.getElementById(this.defaultFieldName),"change")}}]);return e}();e.Dialog=u;e.Ui=d})(this.BX.Desktop.Field.Enum=this.BX.Desktop.Field.Enum||{},BX.UI.EntitySelector,BX,BX,BX.Event);
//# sourceMappingURL=display.bundle.map.js